home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Programming / VisualBuilder / source / VisualBuilder.c < prev    next >
C/C++ Source or Header  |  1997-11-10  |  14KB  |  356 lines

  1. /*** include files ***/
  2. #include <exec/types.h>
  3. #include <exec/memory.h>
  4. #include <exec/libraries.h>
  5. #include <proto/exec.h>
  6. #include <proto/muimaster.h>
  7. #include <libraries/mui.h>
  8. #include <libraries/gadtools.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classusr.h>
  11. #include <proto/utility.h>
  12. #include <utility/utility.h>
  13. #include <utility/tagitem.h>
  14. #include <clib/alib_protos.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18.  
  19. #define REG(x) register __ ## x
  20. #define ASM __asm
  21. #define SAVEDS __saveds
  22.  
  23. #ifndef MAKE_ID
  24. #define MAKE_ID(a,b,c,d) ((((ULONG) (a)) << 24) | (((ULONG) (b)) << 16) | (((ULONG) (c)) << 8) | ((ULONG) (d)))
  25. #endif
  26.  
  27. #define TAGBASE_KLJ (TAG_USER | (9999UL << 16))
  28.  
  29. /* counter for general use */
  30. int i;
  31.  
  32. static const char *entries[] = { "Entry1","Entry2","Entry3", NULL };
  33.  
  34. /* Structure for use in listviews */
  35. struct VBList
  36. { char *Value;
  37.   char *Key;
  38. };
  39.  
  40. struct VBList *vbl;
  41.  
  42.        
  43. /* This structure contains the pointers to all our objects */
  44. struct ObjApp
  45. {
  46.   /* Application and window objects */
  47.   APTR App; APTR ToolBoxWindow; APTR MainWindow; APTR ObjectsWindow;
  48.   APTR Toolbar; APTR MainWinGroup; APTR MenuStrip;
  49.  
  50.   /* The active object */
  51.   APTR actobj;
  52.  
  53.   /* Array with windows created by the user. max is 16 for now */
  54.   APTR UserWin[15];
  55.  
  56.   /* Menu items */
  57.   APTR MenuFile; APTR MenuEdit; APTR MenuView; APTR MenuInsert; APTR MenuTools; APTR MenuHelp;
  58.   APTR FileNew; APTR FileOpen; APTR FileSave; APTR FileSaveAs; APTR FileMakeExe; APTR FileQuit;
  59.   APTR EditCut; APTR EditCopy; APTR EditPaste; APTR EditDelete;
  60.   APTR ViewObjects; APTR ViewToolbox; APTR ViewToolbar;
  61.   APTR InsertWindow;
  62.   APTR ToolsMenuEditor; APTR ToolsOptions;
  63.   APTR HelpContents; APTR HelpAboutVB; APTR HelpAboutMUI;
  64.  
  65.   /* Toolbar buttons */
  66.   APTR ToolBarQuit; APTR ToolBarHelp;
  67.  
  68.   /* Objectswindow objects for notify class*/
  69.   APTR HelpLine; APTR HelpNode; APTR ObjectID; 
  70.  
  71.   /* Objectswindow objects for area class*/
  72.   APTR BackGround; APTR ContextMenu; APTR ControlChar; APTR CycleChain;
  73.   APTR Disabled; APTR Draggable; APTR Dropable; APTR Font; APTR Frame;
  74.   APTR FramePhantomHoriz; APTR FrameTitle; APTR HorizDisappear;
  75.   APTR HorizWeight; APTR InnerBottom; APTR InnerLeft; APTR InnerRight;
  76.   APTR InnerTop; APTR InputMode; APTR MaxHeigth; APTR MaxWidth;
  77.   APTR Selected; APTR ShortHelp; APTR ShowMe; APTR ShowSelState;
  78.   APTR VertDisappear; APTR VertWeight; APTR Weight;  
  79.  
  80.   /* General objects in objectswindow */
  81.   APTR ApplyChanges; APTR ObjListPop; 
  82. };
  83.  
  84. struct ObjApp *a;
  85.  
  86. struct Library *MUIMasterBase;
  87. /*LONG __stack = 35000;*/
  88.  
  89. #include "Prototypes.c"
  90. #include "ObjWinSubs.c"
  91. #include "ListEntries.c"
  92. #include "Menu.c"
  93. #include "MainWin.c"
  94. #include "DropObjClass.c"
  95. #include "HookFuncs.c"
  96. #include "ObjWin.c"
  97. #include "DropAppClass.c"
  98. #include "DropObjSubs.c"
  99. #include "ToolBoxWin.c"
  100. #include "CommonSubs.c"
  101.                                
  102. static VOID ShutDown(char *str)
  103. {
  104.   if (a->App)        MUI_DisposeObject(a->App);
  105.   if (DropButClass)  MUI_DeleteCustomClass(DropButClass);
  106.   if (DropGrpClass)  MUI_DeleteCustomClass(DropGrpClass);
  107.   if (DropRadClass)  MUI_DeleteCustomClass(DropRadClass);
  108.   if (DropCycClass)  MUI_DeleteCustomClass(DropCycClass);
  109.   if (DropChkClass)  MUI_DeleteCustomClass(DropChkClass);
  110.   if (DropTxtClass)  MUI_DeleteCustomClass(DropTxtClass);
  111.   if (DropLstClass)  MUI_DeleteCustomClass(DropLstClass);
  112.   if (DropStrClass)  MUI_DeleteCustomClass(DropStrClass);
  113.   if (DropGauClass)  MUI_DeleteCustomClass(DropGauClass);
  114.   if (DropSclClass)  MUI_DeleteCustomClass(DropSclClass);
  115.   if (DropBalClass)  MUI_DeleteCustomClass(DropBalClass);
  116.   if (DropImgClass)  MUI_DeleteCustomClass(DropImgClass);
  117.   if (DropSldClass)  MUI_DeleteCustomClass(DropSldClass);
  118.   if (DropKnbClass)  MUI_DeleteCustomClass(DropKnbClass);
  119.   if (DropLvlClass)  MUI_DeleteCustomClass(DropLvlClass);
  120.   if (DropNmbClass)  MUI_DeleteCustomClass(DropNmbClass);
  121.  
  122.   if (DropAppClass)  MUI_DeleteCustomClass(DropAppClass);
  123.   if (MUIMasterBase) CloseLibrary(MUIMasterBase);
  124.  
  125.   if (a)             FreeVec(a);
  126.   if (vbl)           FreeVec(vbl);
  127.   
  128.   if (str)
  129.   { puts(str);
  130.     exit(20);
  131.   }
  132.  
  133.   exit(0);
  134. }
  135.  
  136. BOOL BuildGUI(void)
  137.   a->App = DropApplicationObject,
  138.     MUIA_Application_Title,       "Visual Builder v1.0 alpha",
  139.     MUIA_Application_Version,     "$VER: Visual Builder 1.0 (12.06.97)",
  140.     MUIA_Application_Copyright,   "Copyright ©1997 by Jan Klok",
  141.     MUIA_Application_Author,      "Jan Klok <jklok@hotmail.com>",
  142.     MUIA_Application_Description, "A userfriendly application builder",
  143.     MUIA_Application_Base,        "VisualBuilder",
  144.     MUIA_Application_HelpFile,    "VisualBuilder.guide",
  145.     MUIA_Application_Menustrip,   a->MenuStrip,
  146.  
  147.     SubWindow, a->ToolBoxWindow = BuildToolBoxWin(),
  148.     SubWindow, a->MainWindow = BuildMainWin(),
  149.     SubWindow, a->ObjectsWindow = BuildObjWin(),
  150.   End;
  151.  
  152.   if(a->App)
  153.   {
  154.     /* Close application when closegadget of toolbarwindow is hit */
  155.     DoMethod(a->MainWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  156.              a->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  157.  
  158.     /* Install toolbar notifications */
  159.     DoMethod(a->ToolBarQuit, MUIM_Notify, MUIA_Pressed, FALSE,
  160.              a->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  161.  
  162.     DoMethod(a->ToolBarHelp,MUIM_Notify, MUIA_Pressed, FALSE,
  163.              a->App,5,MUIM_Application_ShowHelp,NULL,NULL,"MAIN",1);
  164.  
  165.     /* Install file menu notificatons */
  166.     DoMethod(a->FileQuit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  167.              a->App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  168.  
  169.     /* Install view menu notifications */
  170.     DoMethod(a->ViewObjects, MUIM_Notify, MUIA_Menuitem_Checked, MUIV_EveryTime,
  171.              a->ObjectsWindow, 3, MUIM_Set, MUIA_Window_Open, MUIV_TriggerValue);
  172.  
  173.     DoMethod(a->ObjectsWindow, MUIM_Notify, MUIA_Window_Open, MUIV_EveryTime,
  174.              a->ViewObjects, 3, MUIM_Set, MUIA_Menuitem_Checked, MUIV_TriggerValue);
  175.  
  176.     DoMethod(a->ObjectsWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  177.              a->ObjectsWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  178.  
  179.     DoMethod(a->ViewToolbox, MUIM_Notify, MUIA_Menuitem_Checked, MUIV_EveryTime,
  180.              a->ToolBoxWindow, 3, MUIM_Set, MUIA_Window_Open, MUIV_TriggerValue);
  181.  
  182.     DoMethod(a->ToolBoxWindow, MUIM_Notify, MUIA_Window_Open, MUIV_EveryTime,
  183.              a->ViewToolbox, 3, MUIM_Set, MUIA_Menuitem_Checked, MUIV_TriggerValue);
  184.  
  185.     DoMethod(a->ToolBoxWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  186.              a->ToolBoxWindow, 3, MUIM_Set, MUIA_Window_Open, FALSE);
  187.  
  188.     DoMethod(a->ViewToolbar,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  189.              a->Toolbar,3,MUIM_CallHook,&ShowHideToolBarHook,MUIV_TriggerValue);
  190.  
  191.     /* Install insert menu notifications */
  192.     DoMethod(a->InsertWindow,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  193.              a->MainWindow,3,MUIM_CallHook,&InsertWindowHook,1);
  194.  
  195.     /* Install edit menu notifications */
  196.     DoMethod(a->EditDelete,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  197.              a->MainWindow,3,MUIM_CallHook,&DeleteObjectHook,1);
  198.  
  199.     /* Install help menu notifications */
  200.     DoMethod(a->HelpContents,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  201.              a->App,5,MUIM_Application_ShowHelp,NULL,NULL,"MAIN",1);
  202.  
  203.     DoMethod(a->HelpAboutMUI,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  204.              a->App,2,MUIM_Application_AboutMUI,a->MainWindow);
  205.              
  206.     DoMethod(a->HelpAboutVB,MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
  207.              a->MainWindow,3,MUIM_CallHook,&AboutVBHook,1);
  208.              
  209.     /* Install objects window notifications */
  210.     DoMethod(a->ApplyChanges, MUIM_Notify, MUIA_Pressed, FALSE,
  211.              a->MainWindow, 3, MUIM_CallHook,&ApplyChangesHook,1);
  212.  
  213.     /* Install doubleclick for lists in objects window */
  214.     DoMethod((Object *)XGet(a->ObjListPop,MUIA_Popobject_Object),MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  215.              a->ObjListPop,2,MUIM_Popstring_Close,TRUE);
  216.  
  217.     DoMethod((Object *)XGet(a->BackGround,MUIA_Popobject_Object),MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  218.              a->BackGround,2,MUIM_Popstring_Close,TRUE);
  219.  
  220.     DoMethod((Object *)XGet(a->Font,MUIA_Popobject_Object),MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  221.              a->Font,2,MUIM_Popstring_Close,TRUE);
  222.  
  223.     DoMethod((Object *)XGet(a->Frame,MUIA_Popobject_Object),MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  224.              a->Frame,2,MUIM_Popstring_Close,TRUE);
  225.  
  226.     DoMethod((Object *)XGet(a->InputMode,MUIA_Popobject_Object),MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,
  227.              a->InputMode,2,MUIM_Popstring_Close,TRUE);
  228.  
  229.     /* Insert items in BackGround list */
  230.     for(i=0;backgrounds[i].Key!=NULL;i++)
  231.     { vbl->Key=backgrounds[i].Key;
  232.       vbl->Value=backgrounds[i].Value;
  233.       DoMethod((Object *)XGet(a->BackGround,MUIA_Popobject_Object),MUIM_List_InsertSingle,vbl,MUIV_List_Insert_Bottom);
  234.     }
  235.        
  236.     /* Insert items in Font list */
  237.     for(i=0;fonts[i].Key!=NULL;i++)
  238.     { vbl->Key=fonts[i].Key;
  239.       vbl->Value=fonts[i].Value;
  240.       DoMethod((Object *)XGet(a->Font,MUIA_Popobject_Object),MUIM_List_InsertSingle,vbl,MUIV_List_Insert_Bottom);
  241.     }
  242.  
  243.     /* Insert items in Frame list */
  244.     for(i=0;frames[i].Key!=NULL;i++)
  245.     { vbl->Key=frames[i].Key;
  246.       vbl->Value=frames[i].Value;
  247.       DoMethod((Object *)XGet(a->Frame,MUIA_Popobject_Object),MUIM_List_InsertSingle,vbl,MUIV_List_Insert_Bottom);
  248.     }
  249.  
  250.     /* Insert items in InputMode list */
  251.     for(i=0;inputmodes[i].Key!=NULL;i++)
  252.     { vbl->Key=inputmodes[i].Key;
  253.       vbl->Value=inputmodes[i].Value;
  254.       DoMethod((Object *)XGet(a->InputMode,MUIA_Popobject_Object),MUIM_List_InsertSingle,vbl,MUIV_List_Insert_Bottom);
  255.     }
  256.                 
  257.     /* Open the vb windows */
  258.     set(a->MainWindow,    MUIA_Window_Open, TRUE);
  259.     set(a->ToolBoxWindow, MUIA_Window_Open, TRUE);
  260.     set(a->ObjectsWindow, MUIA_Window_Open, TRUE);
  261.  
  262.     /* Open the first user window */
  263.     set(a->InsertWindow,MUIA_Menuitem_Trigger,TRUE);
  264.     
  265.     return(TRUE);
  266.   }
  267.   else return(FALSE);
  268. }
  269.  
  270. static VOID Initialize(VOID)
  271. {
  272.   if (!(a = AllocVec(sizeof(struct ObjApp), MEMF_PUBLIC|MEMF_CLEAR)))
  273.     ShutDown("No memory for ObjApp structure");
  274.  
  275.   if (!(vbl = AllocVec(sizeof(struct VBList), MEMF_PUBLIC|MEMF_CLEAR)))
  276.     ShutDown("No memory for VBList structure");
  277.  
  278.   if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  279.     ShutDown("Failed to open mui");
  280.  
  281.   if (!(DropAppClass = MUI_CreateCustomClass(NULL, MUIC_Application, NULL, sizeof(struct DropObjData), DropApp_Dispatcher)))
  282.     ShutDown("Couldn't create DropAppClass!");
  283.  
  284.   if (!(DropButClass = MUI_CreateCustomClass(NULL, MUIC_Text, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  285.     ShutDown("Couldn't create DropButClass!");
  286.  
  287.   if (!(DropGrpClass = MUI_CreateCustomClass(NULL, MUIC_Group, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  288.     ShutDown("Couldn't create DropGrpClass!");
  289.  
  290.   if (!(DropStrClass = MUI_CreateCustomClass(NULL, MUIC_String, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  291.     ShutDown("Couldn't create DropStrClass!");
  292.  
  293.   if (!(DropRadClass = MUI_CreateCustomClass(NULL, MUIC_Radio, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  294.     ShutDown("Couldn't create DropRadClass!");
  295.  
  296.   if (!(DropCycClass = MUI_CreateCustomClass(NULL, MUIC_Cycle, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  297.     ShutDown("Couldn't create DropCycClass!");
  298.  
  299.   if (!(DropLstClass = MUI_CreateCustomClass(NULL, MUIC_Listview, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  300.     ShutDown("Couldn't create DropLstClass!");
  301.  
  302.   if (!(DropChkClass = MUI_CreateCustomClass(NULL, MUIC_Image, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  303.     ShutDown("Couldn't create DropChkClass!");
  304.  
  305.   if (!(DropTxtClass = MUI_CreateCustomClass(NULL, MUIC_Text, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  306.     ShutDown("Couldn't create DropLabClass!");
  307.  
  308.   if (!(DropGauClass = MUI_CreateCustomClass(NULL, MUIC_Gauge, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  309.     ShutDown("Couldn't create DropGauClass!");
  310.  
  311.   if (!(DropSclClass = MUI_CreateCustomClass(NULL, MUIC_Scale, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  312.     ShutDown("Couldn't create DropSclClass!");
  313.  
  314.   if (!(DropBalClass = MUI_CreateCustomClass(NULL, MUIC_Balance, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  315.     ShutDown("Couldn't create DropBalClass!");
  316.  
  317.   if (!(DropImgClass = MUI_CreateCustomClass(NULL, MUIC_Image, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  318.     ShutDown("Couldn't create DropImgClass!");
  319.  
  320.   if (!(DropSldClass = MUI_CreateCustomClass(NULL, MUIC_Slider, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  321.     ShutDown("Couldn't create DropSldClass!");
  322.  
  323.   if (!(DropKnbClass = MUI_CreateCustomClass(NULL, MUIC_Knob, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  324.     ShutDown("Couldn't create DropKnbClass!");
  325.  
  326.   if (!(DropLvlClass = MUI_CreateCustomClass(NULL, MUIC_Levelmeter, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  327.     ShutDown("Couldn't create DropLvlClass!");
  328.  
  329.   if (!(DropNmbClass = MUI_CreateCustomClass(NULL, MUIC_Numericbutton, NULL, sizeof(struct DropObjData), DropObj_Dispatcher)))
  330.     ShutDown("Couldn't create DropNmbClass!");
  331.  
  332.   if (!BuildMenu())
  333.     ShutDown("Couldn't create menu!");
  334.  
  335.   if (!BuildGUI())
  336.     ShutDown("Couldn't create application!");
  337. }
  338.  
  339. int main(int argc,char *argv[])
  340. {
  341.   Initialize();
  342.  
  343.   { ULONG sigs = 0;
  344.  
  345.     while (DoMethod(a->App,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  346.     { if (sigs)
  347.       { sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  348.         if (sigs & SIGBREAKF_CTRL_C) break;
  349.       }
  350.     }
  351.   }
  352.  
  353.   ShutDown(NULL);
  354. }
  355.